package cn.powerone.scm.controller;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.powerone.common.annotation.Log;
import cn.powerone.common.core.controller.BaseController;
import cn.powerone.common.core.domain.AjaxResult;
import cn.powerone.common.enums.BusinessType;
import cn.powerone.scm.domain.ScmSupplierAddress;
import cn.powerone.scm.service.IScmSupplierAddressService;
import cn.powerone.common.utils.poi.ExcelUtil;
import cn.powerone.common.core.page.TableDataInfo;

/**
 * 供应商地址Controller
 * 
 * @author PowerOne
 * @date 2025-06-26
 */
@RestController
@RequestMapping("/scm/supplierAddress")
public class ScmSupplierAddressController extends BaseController
{
    @Autowired
    private IScmSupplierAddressService scmSupplierAddressService;

    /**
     * 查询供应商地址列表
     */
    @PreAuthorize("@ss.hasPermi('scm:supplierAddress:list')")
    @GetMapping("/list")
    public TableDataInfo list(ScmSupplierAddress scmSupplierAddress)
    {
        startPage();
        List<ScmSupplierAddress> list = scmSupplierAddressService.selectScmSupplierAddressList(scmSupplierAddress);
        return getDataTable(list);
    }

    /**
     * 导出供应商地址列表
     */
    @PreAuthorize("@ss.hasPermi('scm:supplierAddress:export')")
    @Log(title = "供应商地址", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ScmSupplierAddress scmSupplierAddress)
    {
        List<ScmSupplierAddress> list = scmSupplierAddressService.selectScmSupplierAddressList(scmSupplierAddress);
        ExcelUtil<ScmSupplierAddress> util = new ExcelUtil<ScmSupplierAddress>(ScmSupplierAddress.class);
        util.exportExcel(response, list, "供应商地址数据");
    }

    /**
     * 获取供应商地址详细信息
     */
    @PreAuthorize("@ss.hasPermi('scm:supplierAddress:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(scmSupplierAddressService.selectScmSupplierAddressById(id));
    }

    /**
     * 新增供应商地址
     */
    @PreAuthorize("@ss.hasPermi('scm:supplierAddress:add')")
    @Log(title = "供应商地址", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ScmSupplierAddress scmSupplierAddress)
    {
        return toAjax(scmSupplierAddressService.insertScmSupplierAddress(scmSupplierAddress));
    }

    /**
     * 修改供应商地址
     */
    @PreAuthorize("@ss.hasPermi('scm:supplierAddress:edit')")
    @Log(title = "供应商地址", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ScmSupplierAddress scmSupplierAddress)
    {
        return toAjax(scmSupplierAddressService.updateScmSupplierAddress(scmSupplierAddress));
    }

    /**
     * 删除供应商地址
     */
    @PreAuthorize("@ss.hasPermi('scm:supplierAddress:remove')")
    @Log(title = "供应商地址", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(scmSupplierAddressService.deleteScmSupplierAddressByIds(ids));
    }
}
